package com.plumejob.executor;

import com.alibaba.fastjson.annotation.JSONField;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerKey;

import java.util.Date;
import java.util.Objects;

/**
 * @author : pdl
 * @date : 2021/2/5 17:54
 */
public class PlumeJobDetail {

    private String appName;

    /**
     * 任务名称
     */
    private String jobName;

    /**
     * 是否运行中
     */
    private Integer running = 0;
    /**
     * 是否启用
     */
    private Integer active = 1;
    /**
     * cron表达式
     */
    private String cronExpr;

    /**
     * 执行的方法
     */
    private String jobMethod;
    /**
     * 参数
     */
    private String extraData;
    /**
     * class name
     */
    private String jobClass;
    /**
     * 1 管理后台 2 注解
     */
    private Integer type = 2;
    /**
     * 上一次运行开始时间
     */
    private Date lastFireTime;
    /**
     * 上次运行结束时间
     */
    private Date lastEndTime;
    /**
     * 下一次运行开始时间
     */
    private Date nextFireTime;

    /**
     * 当前执行节点id
     */
    private String address;

    private long modifyTime;

    private String errorMsg;

    private int result;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PlumeJobDetail)) return false;
        PlumeJobDetail that = (PlumeJobDetail) o;
        return Objects.equals(appName, that.appName) && Objects.equals(jobName, that.jobName) && Objects.equals(cronExpr, that.cronExpr) && Objects.equals(jobMethod, that.jobMethod) && Objects.equals(extraData, that.extraData) && Objects.equals(jobClass, that.jobClass) && Objects.equals(address, that.address);
    }

    @Override
    public int hashCode() {
        return Objects.hash(appName, jobName, cronExpr, jobMethod, extraData, jobClass, address);
    }

    @JSONField(serialize=false)
    private Scheduler scheduler;
    @JSONField(serialize=false)
    private Trigger cronTrigger;
    @JSONField(serialize=false)
    private TriggerKey triggerKey;

    public PlumeJobDetail() {
        running = 0;
    }


    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public Integer getRunning() {
        return running;
    }

    public void setRunning(Integer running) {
        this.running = running;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

    public String getCronExpr() {
        return cronExpr;
    }

    public void setCronExpr(String cronExpr) {
        this.cronExpr = cronExpr;
    }

    public String getJobMethod() {
        return jobMethod;
    }

    public void setJobMethod(String jobMethod) {
        this.jobMethod = jobMethod;
    }

    public String getExtraData() {
        return extraData;
    }

    public void setExtraData(String extraData) {
        this.extraData = extraData;
    }

    public String getJobClass() {
        return jobClass;
    }

    public void setJobClass(String jobClass) {
        this.jobClass = jobClass;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Date getLastFireTime() {
        return lastFireTime;
    }

    public void setLastFireTime(Date lastFireTime) {
        this.lastFireTime = lastFireTime;
    }

    public Date getLastEndTime() {
        return lastEndTime;
    }

    public void setLastEndTime(Date lastEndTime) {
        this.lastEndTime = lastEndTime;
    }

    public Date getNextFireTime() {
        return nextFireTime;
    }

    public void setNextFireTime(Date nextFireTime) {
        this.nextFireTime = nextFireTime;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public long getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(long modifyTime) {
        this.modifyTime = modifyTime;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public Scheduler getScheduler() {
        return scheduler;
    }

    public void setScheduler(Scheduler scheduler) {
        this.scheduler = scheduler;
    }

    public Trigger getCronTrigger() {
        return cronTrigger;
    }

    public void setCronTrigger(Trigger cronTrigger) {
        this.cronTrigger = cronTrigger;
    }

    public TriggerKey getTriggerKey() {
        return triggerKey;
    }

    public void setTriggerKey(TriggerKey triggerKey) {
        this.triggerKey = triggerKey;
    }

}
